package com.hxd.otc.module.my.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseActivity;
import com.hxd.otc.common.enums.CountryCodeEnum;
import com.hxd.otc.module.my.bean.RealNameAuthRuleInfoBean;
import com.hxd.otc.module.my.contract.CertificationTypeContract;
import com.hxd.otc.module.my.presenter.CertificationTypePresenter;
import com.hxd.otc.utils.ResourceUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by lzy on 2018/12/5 0005.
 * description ${实名认证类型选择}
 */
public class CertificationTypeActivity extends BaseActivity<CertificationTypePresenter> implements CertificationTypeContract.IView {

    @BindView(R.id.tv_desc)
    TextView mTvDesc;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_certification_type;
    }

    @Override
    protected CertificationTypePresenter createPresenter() {
        return new CertificationTypePresenter(this);
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {
        mPresenter.getRealNameAuthRuleInfo();
    }

    @Override
    protected void initEvent() {
    }

    @OnClick({R.id.tv_china_certification, R.id.tv_other_certification})
    public void onClick(View view) {
        Bundle bundle = new Bundle();
        switch (view.getId()) {
            case R.id.tv_china_certification:
                bundle.putSerializable(RealNameStep2Activity.EXTRA_REAL_NAME_TYPE, CountryCodeEnum.CHINA);
                break;
            case R.id.tv_other_certification:
                bundle.putSerializable(RealNameStep2Activity.EXTRA_REAL_NAME_TYPE, CountryCodeEnum.OTHER);
                break;
        }
        $startActivity(RealNameStep2Activity.class, bundle, true);
    }

    @Override
    public void getRealNameAuthRuleInfoSuccess(ArrayList<RealNameAuthRuleInfoBean> realNameAuthRuleInfoBeans) {

        String v0Desc = "";
        String v1Desc = "";
        String v2Desc = "";

        if (realNameAuthRuleInfoBeans != null && realNameAuthRuleInfoBeans.size() != 0) {
            for (RealNameAuthRuleInfoBean realNameAuthRuleInfoBean : realNameAuthRuleInfoBeans) {
                switch (realNameAuthRuleInfoBean.getCronKey()) {
                    case RealNameAuthRuleInfoBean.V0:
                        v0Desc = realNameAuthRuleInfoBean.getCronValueDesc();
                        break;
                    case RealNameAuthRuleInfoBean.V1:
                        v1Desc = realNameAuthRuleInfoBean.getCronValueDesc();
                        break;
                    case RealNameAuthRuleInfoBean.V2:
                        v2Desc = realNameAuthRuleInfoBean.getCronValueDesc();
                        break;
                }
            }
        }
        mTvDesc.setText(ResourceUtil.getString(R.string.certification_environmental_instructions_for, v0Desc, v1Desc, v2Desc));
    }

    @Override
    public void getRealNameAuthRuleInfoFail(String errMessage) {
        mTvDesc.setText(ResourceUtil.getString(R.string.certification_environmental_instructions_for, "", "", ""));
    }
}
